package com.mstanford.movie.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginExitServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		// 删除Cookie
		Cookie[] cookies = request.getCookies();
		
		for(Cookie cookie : cookies) {
			if("movieInfo".equals(cookie.getName())) {
				cookie.setMaxAge(0);
				response.addCookie(cookie);
				
				break;
			}
		}
		
		// 删除Seesion
		HttpSession session = request.getSession();
		session.invalidate();
		
		response.sendRedirect("index.jsp");
	}
}